$(function() {
	var f=true;
	var f2=true;
	//注册信息验证
	$("input[name='car_id'],input[name='teacher'],input[name='remarks']").blur(function(){
		var flag =true;
		var flag2=true;
		var car_id=$("input[name='car_id']").val();
		var teacher=$("input[name='teacher']").val();		
		var remarks=$("input[name='remarks']").val();
		if(car_id==""){
			flag=flag && false;
		}
		if(teacher==""){
			flag=flag && false;
		}
		
		f=flag;
		if(!(/^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/.test(car_id))){ 
			flag2=flag2 && false;
			 }
		f2=flag2;
	});
	
	
	//为注册按钮绑定点击注册时间  出发regist方法
	$("#payment-button").click(function(){
		if(!f){
			alert("学员信息不能为空！")
		}else if(!f2){
			alert("请输入正确的车牌号！")
		}else{ 
			return car_regist();
		}
	});
})

function car_regist(){
	var car_id=$("input[name='car_id']").val();
	var teacher=$("input[name='teacher']").val();		
	var remarks=$("input[name='remarks']").val();
	$.ajax({
		url:"car/regist",
		data:{"car_id":car_id,"teacher":teacher,"remarks":remarks},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			var flag=data.success;
			if(flag){
				alert("添加成功！");
				window.location.href="select-car.html";
			}else{
				alert(data.message);
			}
		},
		error:function(e){
			alert("添加失败！");
		}
	})
}